#!/bin/bash
# Utiliit aitamaks erinevaid linuxi distroid lihtsamini üles seada
# See skript siin lihtsalt sikutab netist uusima main skripti alla
# 

PROGRAM="Utiliit (starter)"
VERSION="1.0-dev"
#note: this url doesn't exist !
BASE_URL="http://code.google.com/p/ubuntu-utils/files/" #where our scripts are
MAIN_NAME="main" # main script name
WORKINGDIR="$HOME/Utils"
main="$WORKINGDIR/main"
use_local_files="yes" #use scripts in current dir instead of downloading them

# Set Colors
BOLD="\033[1;10m"
RED="\033[0;31m"
REDBOLD="\033[1;31m"
GREEN="\033[0;32m"
GREENBOLD="\033[1;32m"
YELLOW="\033[0;33m"
YELLOWBOLD="\033[1;33m"
BLUE="\033[0;34m"
BLUEBOLD="\033[1;34m"
ENDCOLOR="\033[0m"

function print()
{	#usage: print "text you want to print" color_name
	#possible colors: search for "Set Colors" line and use var names in lover case
	#example: print "Hello World" redbold
	eval echo -n -e \$${2^^}; echo -e "$1"$ENDCOLOR  
}


mkdir "$WORKINGDIR" > "/dev/null" 2>&1 # FIXME !!! Not good way to do it !!!

print "$PROGRAM $VERSION " bold
print "## Downloading main script file ##" bluebold
if [ "$use_local_files" = "yes" ]; then
	cp ./main $main
	print "using local file" yellow
else
	wget "$BASE_URL$MAIN_NAME" -nv -O $main
	if [ $? = "0" ]; then
		print "Main script downloaded" green
	elif [ $? = "8" ]; then
		print "Error 404: Not Found" red
		print "Program Terminated." redbold
		exit
	else
		print "Can't download main script" red
		print "Check your internet connection" red
		print "Program Terminated." redbold
		exit
	fi
fi

print "## Starting main script ##" bluebold
source $main #run main script
# source command works similary to python's import
